package cn.flying.cloud.system.tenant.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.system.tenant.entity.SysTenantInfo;
import cn.flying.cloud.system.tenant.service.SysTenantInfoService;


/**
 * 租户信息表 前端控制器
 *
 * @author: admin
 * @date: 2024-06-13 13:15:43
 * @version: 1.0
 */
@RestController
@RequestMapping("/system/tenant")
public class SysTenantInfoController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysTenantInfoService sysTenantInfoService;

    /**
     * 分页查询租户信息表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse<SysTenantInfo> page(@RequestBody PageRequest<SysTenantInfo> request) {
        return sysTenantInfoService.getPageList(request);
    }

    /**
     * 列表查询租户信息表数据
     *
     * @param sysTenantInfo
     * @return
     */
    @PostMapping("list")
    public Rt<?> list(@RequestBody SysTenantInfo sysTenantInfo) {
        List<SysTenantInfo> list = sysTenantInfoService.getList(sysTenantInfo);
        return Rt.success(list);
    }

    /**
     * 查询租户信息表详情数据
     *
     * @param sysTenantInfo
     * @return
     */
    @PostMapping("detail")
    public Rt<?> detail(SysTenantInfo sysTenantInfo) {
        return Rt.success(sysTenantInfoService.getOneObj(sysTenantInfo));
    }

    /**
     * 根据主键ID查询租户信息表详情数据
     *
     * @param id
     * @return
     */
    @PostMapping("getById")
    public Rt<?> getById(Long id) {
        SysTenantInfo sysTenantInfo = sysTenantInfoService.getById(id);
        return Rt.success(sysTenantInfo);
    }

    /**
     * 保存租户信息表数据
     *
     * @param sysTenantInfo
     * @return
     */
    @PostMapping("save")
    public Rt<?> save(@RequestBody SysTenantInfo sysTenantInfo) {
        if (Objects.isNull(sysTenantInfo.getId())) {
            // 新增
            sysTenantInfoService.createObj(sysTenantInfo);
        } else {
            // 更新
            sysTenantInfoService.updateObj(sysTenantInfo);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除租户信息表数据
     *
     * @param sysTenantInfo
     * @return
     */
    @PostMapping("delete")
    public Rt<?> delete(SysTenantInfo sysTenantInfo) {
        sysTenantInfoService.deleteObj(sysTenantInfo);
        return Rt.success("删除成功！");
    }

    /**
     * 根据Id删除
     *
     * @param id
     * @return
     */
    @GetMapping("deleteById/{id}")
    public Rt<?> deleteById(@PathVariable("id") Long id) {
        sysTenantInfoService.deleteById(id);
        return Rt.success("删除成功！");
    }
}
